import React from "react";
import {getVoPrefixAndPostfix} from "../utils/CommUtil";

class FunReturnVo extends React.Component {

    constructor(props) {
        super(props);
    }

    componentDidMount() {

    }

    onSelectVo = (_parentVo, _resObj) => {

        let {parentVo} = this.props
        var newParentVo = JSON.parse(JSON.stringify(parentVo))

        newParentVo.next = _parentVo

        this.props.onSelectVo(newParentVo, _resObj)
    }

    render() {

        let {resObj, parentVo} = this.props

        let {prefix, postfix} = getVoPrefixAndPostfix(resObj)

        return (
            <span>
                {prefix}
                <span onClick={
                    () => {

                        var newParentVo = JSON.parse(JSON.stringify(parentVo))
                        delete newParentVo.next
                        this.props.onSelectVo(newParentVo, resObj)

                    }
                } className='fun-return-vo'>{resObj.name ? resObj.name : ''}&nbsp;</span>
                {postfix}
                {resObj.next || resObj.paradigm == 'yes'
                    ?
                    (<span>&lt;<FunReturnVo parentVo={resObj} resObj={resObj.next || {}} onSelectVo={this.onSelectVo} key={'FunReturnVo_key_'+resObj.id} />&gt;</span> )
                    : ''
                }
            </span>
        )
    }
}

export default FunReturnVo;

